
// 机构后台机构课程列表
var categoryData = require("../../staticData/categoryData");

exports.course_management = function (req, res) {

    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;

    //最终结果
    var resultData = {};
    var skip = restfulParams.skip == undefined ? 0 : restfulParams.skip;

    var limit = restfulParams.limit == undefined ? config.publicConfig.LIMIT : restfulParams.limit;

    //任务流创建
    async.waterfall([
            //1.机构课程列表
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.search_course + "/oc_oid/" + restfulParams.oc_oid+"/oc_type/"+restfulParams.oc_type+"/skip/" + skip + "/limit/" + limit+"/sort_order/oc_create_time-desc",
                        method: 'POST',
                        data: {
                            fields: [ "oc_id","oc_title", "oc_new_price", "oc_course_count","oc_cid"].join(",")
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }

                        resultData.organizationCourseList = data.data;
                        cb();
                    }
                );

            },
            function(cb){

                for(var i=0;i<resultData.organizationCourseList.length;i++){
                    resultData.organizationCourseList[i].oc_name = categoryData[resultData.organizationCourseList[i].oc_cid];
                }

                cb();

            },

        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

}